import {request, writeLog} from "@/libs/core.js"
import { Message } from 'element-ui'
/**
会员登录校验逻辑
@param args{account:xxx. loginpw:xxx, vcode:xxxx}
****************************************************************/
const getList = async(args) => {
  const data = await request({url:'/user/dolist', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data;
  }
  return false
}

const doRoleIds = async(args) => {
	const data = await request({url:'/user/doroleids', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data.roles;
  }
  return [];
}

const doSave = async(args) => {
	const data = await request({url:'/user/dosave', data:args, method:'post'});
	if (data && data.code == 0) {
		if (!args.id) {
			Message({message: '账号信息添加成功', type: 'success', duration: 3 * 1000});
		} else {
			Message({message: '账号信息编辑成功', type: 'success', duration: 3 * 1000});
		}
		return true;
	}
  return false;
}

const getAccess = async(args) => {
	const data = await request({url:'/user/doaccess', data:args, method:'post'});
  if (data && data.code == 0 ) {
    return data.access;
  }
  return [];
}

const setAccess = async(args) => {
	const data = await request({url:'/user/setaccess', data:args, method:'post'});
  if (data && data.code == 0 ) {
  	Message({message: '账号授权处理成功', type: 'success', duration: 3 * 1000});
    return true;
  }
  return false;
}

const doMine = async(args) => {
  const data = await request({url:'/user/domine', data:args, method:'post'});
  if (data && data.code == 0 ) {
    Message({message: '账号编辑处理成功', type: 'success', duration: 3 * 1000});
    return true;
  }
  return false;
}

export default {
	getList,doSave,doRoleIds,getAccess,setAccess,doMine
};